#pragma once

#include <glibmm.h>
#include <assert.h>
#include "../Shared/GObjHelpers.hpp"

typedef struct _OVERLAPPED OVERLAPPED;

namespace EGlib
{
  class PipeBase
  {
  public:
    PipeBase(bool is_write_pipe);
    ~PipeBase();

    void* get_read_handle() { return read_pipe; }
    void* get_write_handle() { return write_pipe; }

    void* get_overlapped_io_done_event() { return overlapped_io_done_event; }

  protected:
    void cleanup();

    void *read_pipe;
    void *write_pipe;

    void *overlapped_io_done_event;
    OVERLAPPED *overlapped;
  };

  class WritePipe : public PipeBase
  {
  public:
    WritePipe()
      : PipeBase(true)
    {
    }

    void write_overlapped(void *buffer,int size);    
  };

  class ReadPipe : public PipeBase
  {
  public:
    ReadPipe()
      : PipeBase(false)
    {
    }

    void read_overlapped(void *dest,int max_size);
    // returns -1 if the end of the file was reached.
    int get_read_size();
  };
}
